package com.itheima.d3_tcp.no2;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

//目标：掌握tcp服务端多收消息
public class ServerDemo02 {
    public static void main(String[] args) throws Exception {
        //1.创建ServerSocket对象，给服务端自己指定端口10004
        ServerSocket server = new ServerSocket(10004);

        //2.获取客户端与服务端的连接
        Socket socket = server.accept();
        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        //3.循环获取数据
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println("客户端发送的数据：" + line);
        }

        //4.释放资源
        socket.close();
        server.close();
    }
}
